package com.example.alienware.a115gyh;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.xdw.ui_demo.beans.Dish;
import com.xdw.ui_demo.recyclerView.RecyclerViewActivity;
import com.xdw.ui_demo.retrofitservice.RetrofitService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    private EditText usernameView, passwordView;
    private Button loginButton;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        loginButton =findViewById(R.id.button);
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent=new Intent();
                intent.setClass(MainActivity.this,HomeActivity.class);
                startActivity(intent);

                Retrofit retrofit = new Retrofit.Builder().baseUrl("http://172.17.7.95:8080/MenuAPIDemo/").addConverterFactory(GsonConverterFactory.create())
                        .build();

                RetrofitService retrofitService = retrofit.create(RetrofitService.class);

                Call<List<Dish>>dishesCall
                        =retrofitService.getDishes();

                dishesCall.enqueue(new Callback<List<Dish>>() {
                    @Override
                    public void onResponse(Call<List<Dish>> call, Response<List<Dish>> response) {
                        List<Dish>dishes =response.body();
                        Toast.makeText(MainActivity.this,"dish" +dishes.size(),Toast.LENGTH_SHORT).show();

                    }

                    @Override
                    public void onFailure(Call<List<Dish>> call, Throwable t) {
                        Toast.makeText(MainActivity.this,t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();


                    }
                });

            }
        });

    }
}
